package cn.com.customer.manager.ui.message.email

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import cn.com.customer.manager.R
import cn.com.customer.manager.adapter.EmailAttachmentAdapter
import cn.com.customer.manager.base.BaseActivity
import cn.com.customer.manager.bean.Attachments
import cn.com.customer.manager.bean.EmailInfo
import cn.com.customer.manager.bean.RequestBean
import cn.com.customer.manager.http.BaseApi
import cn.com.customer.manager.http.subscriber.TipRequestSubscriber
import com.chad.library.adapter.base.BaseQuickAdapter
import com.xuexiang.xhttp2.XHttp
import com.xuexiang.xhttp2.model.ApiResult
import kotlinx.android.synthetic.main.activity_email_detail.*
import kotlinx.android.synthetic.main.layout_base_toolbar.*

class EmailDetailActivity : BaseActivity(), BaseQuickAdapter.OnItemClickListener, BaseQuickAdapter.OnItemChildClickListener {
    private lateinit var mAdapter: EmailAttachmentAdapter
    private var mData:MutableList<Attachments> = mutableListOf()
    override fun getLayoutId(): Int =R.layout.activity_email_detail

    override fun initView(savedInstanceState: Bundle?) {
        toolbar_title.text = "邮件详情"
        initData()
        initRv()
//        email_send.setOnClickListener{
////            var parames:MutableMap<String,String> = mutableMapOf()
////
////            XHttpProxy.proxy(BaseApi.IMessage::class.java, ThreadType.TO_IO).smsSend(RequestBean(parames)).subscribeWith(object : TipRequestSubscriber<ApiResult<EmailInfo>>() {
////                override fun onSuccess(t: ApiResult<EmailInfo>?) {
////                    t?.let {
////                        if (it.data!=null){
////                            email_Type.text=t.data.mailTitle
////                            email_Date.text=t.data.sendDate
////                            email_sender.text=t.data.sendName
////                            email_num.text=t.data.sendMobile
////                            email_content.text=t.data.mailContent
////                            mData= t.data.mailAttachments as MutableList<Attachments>
////                        }
////                    }
////                }
////            })
////        }
    }

    private fun initData() {
        var parames:MutableMap<String,String> = mutableMapOf()
        parames["mailId"] = intent.getStringExtra("data")
        val request = XHttp.custom()
        request.call(request.create(BaseApi.IMessage::class.java)
                .mailDetail(RequestBean(parames)))
                .subscribeWith(object : TipRequestSubscriber<ApiResult<EmailInfo>?>() {
                    override fun onSuccess(apiResult: ApiResult<EmailInfo>?) {
                        apiResult?.let {
                            if (it.data!=null){
                                email_Type.text=it.data.mailTitle
                                email_Date.text=it.data.sendDate
                                email_sender.text=it.data.sendName
                                email_num.text=it.data.sendMobile
                                email_content.text=it.data.mailContent
                                mData= it.data.mailAttachments as MutableList<Attachments>
                            }
                        }
                    }
                })
    }

    private fun initRv() {
        email_rv.layoutManager = GridLayoutManager(this, 5)
        mAdapter = EmailAttachmentAdapter(R.layout.item_attachment_list)
        email_rv.adapter = mAdapter
        mAdapter.onItemClickListener = this
        mAdapter.onItemChildClickListener = this
        mAdapter.addData(mData)
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {

    }

    override fun onItemChildClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {

    }


}
